#ifndef DATABASESERVICE_H
#define DATABASESERVICE_H

#include "core_global.h"
#include <mysql++.h>
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>
#include <boost/asio/detail/config.hpp>

class MysqlConnectionPool;
class AsyncService;

class CORE_EXPORT DatabaseService :
        protected boost::noncopyable
{
public:
    typedef boost::shared_ptr< MysqlConnectionPool > PoolPtr;

    typedef boost::function< void (mysqlpp::Connection *) > Implement;

public:
    DatabaseService(AsyncService &service);
    ~DatabaseService();

    int init(const std::string &db,
             const std::string &host,
             const std::string &user,
             const std::string &password,
             unsigned short port);

    void operation(BOOST_ASIO_MOVE_ARG(Implement) impl);

protected:
    void implementation(Implement impl);

private:
    AsyncService &m_service;

    PoolPtr m_pool;
};

#endif // DATABASESERVICE_H
